package com.jd.finance.core.controller.api;


import com.jd.finance.core.pojo.request.CompAuthRequest;
import com.jd.finance.core.service.CompanyService;
import com.jd.finance.result.BaseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 公司表 前端控制器
 * </p>
 *
 * @author LiQingBo
 * @since 2022-05-17
 */
@Api(tags = "企业中心")
@Slf4j
@RestController
@RequestMapping("/api/core/compCenter")
public class CompanyController {

    @Resource
    private CompanyService companyService;

    @ApiOperation("根据uid查询企业id")
    @GetMapping("/getCompId")
    public BaseResult getCompId(Integer uid) {
        if (uid == null) {
            log.error("用户id为空！");
            return BaseResult.error().message("用户id为空");
        }
        return companyService.getCompId(uid);
    }


    @ApiOperation("进行企业认证")
    @GetMapping("/compCertifica")
    public BaseResult compCertifica(CompAuthRequest compAuthRequest) {
        Integer uid = compAuthRequest.getUid();
        String compUser = compAuthRequest.getCompUser();
        String compAddress = compAuthRequest.getCompAddress();
        String compNumber = compAuthRequest.getCompNumber();
        String compName = compAuthRequest.getCompName();
        String businessScope = compAuthRequest.getBusinessScope();
        String compPhone = compAuthRequest.getCompPhone();
        if (!StringUtils.isAllBlank(String.valueOf(uid), compUser, compAddress,
                compNumber, compName, businessScope, compPhone)) {
            log.error("认证信息为空！");
            return BaseResult.error().message("认证信息为空!");
        }
        return companyService.compCertifica(uid, compUser, compAddress, compNumber,
                compName, businessScope, compPhone);

    }

    @ApiOperation("查询企业信息")
    @GetMapping("/getCompInfo")
    public BaseResult getCompInfo(Integer uid) {
        if (uid == null) {
            log.error("uid为空!");
            return BaseResult.error().message("信息为空!");
        }
        return companyService.getCompInfo(uid);
    }

    @ApiOperation("查询企业是否认证")
    @GetMapping("getCompCertitica")
    public BaseResult getCompCertitica(Integer uid) {
        if (uid == null) {
            log.error("uid为空!");
            return BaseResult.error().message("uid为空!");
        }
        return companyService.getCompCertitica(uid);
    }

}

